﻿using System;
using System.Diagnostics;

class Program
{
    static Process? pythonProcess;

    static void Main()
    {
        // 启动Python脚本
        StartPythonScript();

        // 等待用户输入来关闭Python进程
        Console.WriteLine("按任意键关闭Python进程...");
        Console.ReadKey();

        // 关闭Python进程
        StopPythonScript();
    }

    static void StartPythonScript()
    {
        pythonProcess = new Process();
        pythonProcess.StartInfo.FileName = "python";
        pythonProcess.StartInfo.Arguments = " D:/Project/PythonProject/Flaskbackend/run.py";
        pythonProcess.Start();
    }

    static void StopPythonScript()
    {
        if (pythonProcess != null && !pythonProcess.HasExited)
        {
            pythonProcess.Kill();
            pythonProcess.Dispose();
            Console.WriteLine("Python进程已关闭。");
        }
        else
        {
            Console.WriteLine("Python进程未运行。");
        }
    }
}